package com.allwees.support.marketing.listener;

import com.allwees.support.marketing.handler.PriceAdjustor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author Daniel
 * @Version 1.0.0
 * @Description 数据库加价规则修改后，刷新所有进程中缓存的加价规则信息
 * @CreateTime 2020/9/4 11:51
 */
@Slf4j
@Component
public class PriceRuleUpdatedListener {

    @Resource
    private PriceAdjustor priceAdjustor;

    @RabbitListener(
                    bindings = @QueueBinding(value = @Queue(), exchange = @Exchange(value = "ex.Product.PriceRule",type = ExchangeTypes.FANOUT))
    )
    public void process(String payload) {
        log.info(">>>>>>>>> price adjust rule changed,send broadcast message.");
        priceAdjustor.init();
    }
}
